package com.xiaoma.lock;

public class SynchronizedDemo {

    private static final Object LOCK = new Object();

    public static void main(String[] args) throws InterruptedException {

        int n = 10;
        Thread[] threads = new Thread[n];

        for (int i = 0; i < n; i++) {
            threads[i] = new Thread(() -> {
                synchronized (LOCK) {
                    System.out.println(Thread.currentThread().getName() + "get lock");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }


        synchronized (LOCK) {
          System.out.println("静态代码块");
            for (int i = 0; i < n; i++) {
                threads[i].start();
//                Thread.sleep(200);
            }
        }
    }

}
